<template>
  <div>
    <el-table
      :data="bannerlist"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="用户编号"> </el-table-column>
      <el-table-column prop="title" label="分类名称"></el-table-column>
     <el-table-column label="图片">
        <template v-slot="scoped">
          <div>
            <img :src="$pre + scoped.row.img" alt="" class="oimg">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template v-slot="scoped">
          <div>
            <el-button type="primise" v-if="scoped.row.status == 1"
              >启 动</el-button
            >
            <el-button type="primise" v-else>禁 用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot="scoped">
          <div>
            <el-button type="primise" @click="edit(scoped.row.id)"
              >编 辑</el-button
            >
            <el-button type="primise" @click="del(scoped.row.id)"
              >删 除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { bannerDel} from "../../../request/api.js" 
import {sucessAlert,warningAlert} from "../../../utils/alert.js"

export default {
  props: [],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      bannerlist: "banner/list",
    }),
  },
  methods: {
    ...mapActions({
      bannerasynclist: "banner/acyncChangeList",
    }),
    edit(id) {
        this.$emit("edit",id)
    },
     del(id){
         bannerDel({id:id}).then(res=>{
            if(res.data.code==200){
                sucessAlert(res.data.msg);
                 this.bannerasynclist();
            }else{
                warningAlert(res.data.msg)
            }
        })
    }
  },
  mounted() {
    this.bannerasynclist();
  },
};
</script>
<style scoped>
.oimg{
  width: 150px;
  height: 150px;
}
</style>